home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: willer@carolian.com (Steve Willer)
- Newsgroups: comp.std.c++
- Subject: auto_ptr: no operator bool()?
- Date: 6 Mar 1996 19:30:16 GMT
- Organization: Carolian Systems, Toronto ON
- Sender: news@sq.com (News Administrator)
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <313ddfd9.16044605@sqarc.sq.com>
- NNTP-Posting-Host: taumet.eng.sun.com
- Content-Type: text
- Content-Length: 1887
- X-Lines: 41
- X-Newsreader: Forte Agent .99d/32.182
- Originator: clamage@taumet
-
- I hope I don't sound like I'm second-guessing people who are likely much more
- experienced than I am in library design, but I have another question about
- auto_ptrs.
-
- Specifically, the (April '95) draft standard auto_ptr doesn't have an operator
- bool() function in it, making it inconvenient to write "if (ptr)" type
- constructs. Is there some sort of reason for that? I know that implicit type
- conversion is generally a bad thing, but I can't see how this one would be
- particularly dangerous (also, can the new explicit keyword be used on the
- return type?).
-
- Now, Meyers's latest book describes an auto_ptr that has member templates, so
- obviously the April WP does not have the latest auto_ptr, but I get the
- impression even the current auto_ptr doesn't have an operator bool(). My
- reading of Meyers's discussion of smart_ptrs mentions that operator bool()
- would allow comparison of two different types of auto_ptrs, but the latest
- iostream standard has an operator bool() and an operator!() defined. So why not
- be consistent?
-
- In fact, as another idea, what about defining a new class, say, explicit_bool?
- explicit_bool would have an operator bool() defined, but would also have an
- operator==(const explicit_bool &rhs) and operator!=(const explicit_bool &rhs)
- defined as a private function. It would also have operator!() return an
- explicit_bool. This way, constructs such as "if (myptr)" and "if (!myptr)"
- would work, but "if (myptr==otherptr)" and "if (myptr != otherptr)" wouldn't
- compile.
-
- Just a thought, anyway. I'm sure there are holes in that idea.
-
-
-
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-